package com.hermes.biz.service.message;

import java.util.HashMap;
import java.util.Map;

import com.hermes.biz.common.model.message.PostMessageUnitDO;
import com.hermes.biz.common.util.message.UserEventRepoUtil;

public class MessageReceiverServiceImpl implements MessageReceiverService {

	private UserEventRepoUtil userEventRepo;
	
	public void init(){
		userEventRepo = UserEventRepoUtil.getUserEventMapUtil();
	}
	
	public Map<Long,PostMessageUnitDO> getPostMessageInfo() {

		HashMap<Long,PostMessageUnitDO>  resultMap = userEventRepo.getUserMessageMap();
		if(resultMap!=null
				&& resultMap.size()>0){
			
			return resultMap;
		}
		return new HashMap<Long,PostMessageUnitDO> ();
	}

	public boolean removePostedMessageInfo(long userId) {
		
		HashMap<Long,PostMessageUnitDO> currentMap = userEventRepo.getUserMessageMap();
		if(currentMap!=null && !currentMap.isEmpty() && currentMap.get(userId)!=null){
			currentMap.remove(currentMap.get(userId));
			return true;
		}
		return false;
	}

	
	public PostMessageUnitDO getPostMessageInfoByUserId(long userId) {

		PostMessageUnitDO resultDO = userEventRepo.getIdNumInMap(userId);
		if(resultDO!=null
				&& (resultDO.getReply()>0
						||resultDO.getComment()>0
						||resultDO.getFans()>0)){
			return resultDO;
		}
		return new PostMessageUnitDO();
	}
	
	public UserEventRepoUtil getUserEventRepo() {
		return userEventRepo;
	}

	public void setUserEventRepo(UserEventRepoUtil userEventRepo) {
		this.userEventRepo = userEventRepo;
	}


}
